import axios from '../utils/request'
import qs from 'qs'

// 验证码
export function captcha() {
  return axios({
    url: 'admin/captcha',
    method: 'get',
    responseType: 'blob'
  })
}

//登录
export function loginBlog(params) {
  return axios.post('admin/login', qs.stringify(params))
}

export const loginBlog1 = (params) => {
  return axios({
    url: 'admin/login',
    method: 'post',
    data: params,
    transformRequest: [
      function (data) {
        let ret = ''
        for (let it in data) {
          ret +=
            encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
        }
        return ret
      }
    ],
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
    .then((res) => res.data)
    .catch((error) => {
      console.log(error)
    })
}

//首页数据
export const indexData = () => {
  return axios.get('admin/indexData').then((res) => res.data)
}

//分类列表
export const category = () => {
  return axios.get('admin/category').then((res) => res.data)
}

//标签列表
export const tag = () => {
  return axios.get('admin/tag').then((res) => res.data)
}

//添加文章
export const article = (param) => {
  return axios.post('admin/article', param).then((res) => res.data)
}

//文章列表
export const articleList = (param) => {
  return axios.get('admin/article', { params: param }).then((res) => res.data)
}

//文章详情
export const articleDetail = (param) => {
  return axios.get('admin/article/' + param).then((res) => res.data)
}

// mockjs
export const aaaList = () => {
  return axios.get('/aaa').then((res) => res.data)
}
